import tensorflow as tf
import os
from common import show_picture

if __name__ == '__main__':
    os.environ["TF_CPP_MIN_LOG_LEVEL"] = '2'
    image_path = './lenna.png'

    # 读取图片数据
    image = tf.io.read_file(image_path)
    image = tf.image.decode_png(image)

    show_picture(image, 'lenna.png')

    central_crop_image = tf.image.central_crop(image, central_fraction=0.5)
    show_picture(central_crop_image, 'central_crop_image_lenna.png')

    # 将图像数据进行编码
    central_crop_image = tf.image.encode_png(central_crop_image)
    # 将编码后的数据保存到文件
    tf.io.write_file('central_crop_image_lenna.png', central_crop_image)

